#ifndef HOBJECT_H
#define HOBJECT_H

#include <QObject>
#include <QVariant>
#include <QVector>
#include <QString>
#include <QUuid>

class HObject
{
public:
    HObject(const QString& type){
        mpParent = nullptr;
        msType = type;
        msGraType = "";
        mvctChild.clear();
        mhashProp.clear();
        QUuid::createUuid().toString();
        msID = QUuid::createUuid().toString();

    }
    HObject(){
        mpParent = nullptr;
        msType = "undifinedtype";
        msGraType = "";
        mvctChild.clear();
        mhashProp.clear();
        QUuid::createUuid().toString();
        msID = QUuid::createUuid().toString();
    }
    virtual ~HObject(){
    }

    QString getName(){
        return msName;
    }
    virtual void setName(const QString& name){
        msName = name;
    }

    QString getType(){
        return msType;
    }
    void setType(const QString& type){
        msType = type;
    }

    QString getGraType(){
        return msGraType;
    }

    void setGraType(const QString& type){
        msGraType = type;
    }

    QString getUUID(){
        return msID;
    }

    QVariant getProp(const QString &key)
    {
        return mhashProp.value(key);
    }

    void setProp(const QString &key, QVariant var)
    {
        if(mhashProp.contains(key))mhashProp.remove(key);

        mhashProp.insert(key,var);
    }

    QStringList getPropKeys()
    {
        return mhashProp.keys();
    }

    void removeProp(const QString &key)
    {
        mhashProp.remove(key);
    }

    bool setDataParent(HObject* par){
        if(getParent() == nullptr){
            mpParent = par;
            mpParent->addChild(this);
            return true;
        }
        return false;
    }
    HObject* getParent(){
        return mpParent;
    }
    void addChild(HObject* p){
        if(nullptr == p)return;

        if(mvctChild.contains(p)){
            return;
        }

        mvctChild.append(p);
    }
    bool removeChild(HObject* p){
        return mvctChild.removeOne(p);
    }
    QVector<HObject*> getChildren(){
        return mvctChild;
    }


protected:
    QString msName;
    QString msType;
    QString msGraType;
    QString msID;
    QHash<QString,QVariant> mhashProp;
    HObject* mpParent;
    QVector<HObject*> mvctChild;

};

#endif // HOBJECT_H
